﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
    public static class DelegateExtension
    {
        public static Delegate RemoveAll(this Delegate dlg, Func<Delegate, bool> pred)
        {
            return Delegate.Combine(dlg.GetInvocationList()
                .Where(pred.Invert())
                .ToArray());
        }

        public static IEnumerable<Delegate> Where(this Delegate dlg, Func<Delegate, bool> pred)
        {
            return dlg.GetInvocationList()
                .Where(pred);
        }
    }
}
